package logic

import (
	"context"
	"fmt"
	"library/models/mysql"

	"library/library/internal/svc"
	"library/library/library"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowActivityLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowActivityLogic {
	return &ShowActivityLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowActivityLogic) ShowActivity(in *library.ShowActivityRequest) (*library.ShowActivityResponse, error) {
	// todo: add your logic here and delete this line

	var activity mysql.Activity
	err := mysql.DB.Debug().Where("id = ?", in.Id).Find(&activity).Error
	if err != nil {
		return nil, fmt.Errorf("查看活动详情失败")
	}
	return &library.ShowActivityResponse{
		Title:   activity.Title,
		Context: activity.Context,
	}, nil
}
